package com.internal.Search.client;

import java.util.List;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.datepicker.client.DateBox;
import com.google.gwt.user.datepicker.client.DatePicker;
import com.internal.Internalhibernate.client.SecUsers;
import com.internal.SharedModule.client.MLLicensesSearchBean;

public class SearchContent extends Composite {

	public static FlexTable flexTable;

	public SearchContent() {
		VerticalPanel mainPanel = new VerticalPanel();
		mainPanel.setStyleName("req-main-panel");
		mainPanel.setSpacing(10);

		HorizontalPanel panel1 = new HorizontalPanel();

		HorizontalPanel panelPro = new HorizontalPanel();
		HTML htmlPro = new HTML("المهنة:");
		htmlPro.setStyleName("req-title1");
		SuggestProOrcale proSuggestion = new SuggestProOrcale();
		SuggestBox boxPro = new SuggestBox(proSuggestion);

		panelPro.add(htmlPro);
		panelPro.setCellHorizontalAlignment(htmlPro,
				HasHorizontalAlignment.ALIGN_RIGHT);
		panelPro.add(boxPro);
		panelPro.setCellHorizontalAlignment(boxPro,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel1.add(panelPro);
		panel1.setCellHorizontalAlignment(panelPro,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel1.add(new HTML("&nbsp"));
		panel1.add(new HTML("&nbsp"));
		panel1.add(new HTML("&nbsp"));

		HorizontalPanel panelFromLice = new HorizontalPanel();
		HTML htmlFromLice = new HTML("من رقم:");
		htmlFromLice.setStyleName("req-title");
		final TextBox txtFromLice = new TextBox();

		panelFromLice.add(htmlFromLice);
		panelFromLice.setCellHorizontalAlignment(htmlFromLice,
				HasHorizontalAlignment.ALIGN_RIGHT);
		panelFromLice.add(txtFromLice);
		panelFromLice.setCellHorizontalAlignment(txtFromLice,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel1.add(panelFromLice);
		panel1.setCellHorizontalAlignment(panelFromLice,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel1.add(new HTML("&nbsp"));
		panel1.add(new HTML("&nbsp"));
		panel1.add(new HTML("&nbsp"));

		HorizontalPanel panelcomfirm = new HorizontalPanel();
		HTML htmlcomfirm = new HTML("الحالة:");
		htmlcomfirm.setStyleName("req-title");
		ListBox listBoxConfirm = new ListBox();
		listBoxConfirm.setStyleName("req-title2");
		listBoxConfirm.addItem("مؤكد", "1");
		listBoxConfirm.addItem("غير مؤكد", "0");

		panelcomfirm.add(htmlcomfirm);
		panelcomfirm.setCellHorizontalAlignment(htmlcomfirm,
				HasHorizontalAlignment.ALIGN_RIGHT);
		panelcomfirm.add(listBoxConfirm);
		panelcomfirm.setCellHorizontalAlignment(listBoxConfirm,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel1.add(panelcomfirm);
		panel1.setCellHorizontalAlignment(panelcomfirm,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel1.add(new HTML("&nbsp"));
		panel1.add(new HTML("&nbsp"));
		panel1.add(new HTML("&nbsp"));

		HorizontalPanel panelFromDate = new HorizontalPanel();
		HTML htmlFromDate = new HTML("من تاريخ:");
		htmlFromDate.setStyleName("req-title1");
		DateBox datePickerFromDate = new DateBox();

		panelFromDate.add(htmlFromDate);
		panelFromDate.setCellHorizontalAlignment(htmlFromDate,
				HasHorizontalAlignment.ALIGN_RIGHT);
		panelFromDate.add(datePickerFromDate);
		panelFromDate.setCellHorizontalAlignment(datePickerFromDate,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel1.add(panelFromDate);
		panel1.setCellHorizontalAlignment(panelFromDate,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel1.add(new HTML("&nbsp"));
		panel1.add(new HTML("&nbsp"));
		panel1.add(new HTML("&nbsp"));

		HorizontalPanel panelLiceNumber = new HorizontalPanel();
		HTML htmlLiceNumber = new HTML("رقم الرخصه:");
		htmlLiceNumber.setStyleName("req-title1");
		TextBox txtLiceNumber = new TextBox();

		panelLiceNumber.add(htmlLiceNumber);
		panelLiceNumber.setCellHorizontalAlignment(htmlLiceNumber,
				HasHorizontalAlignment.ALIGN_RIGHT);
		panelLiceNumber.add(txtLiceNumber);
		panelFromDate.setCellHorizontalAlignment(txtLiceNumber,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel1.add(panelLiceNumber);
		panel1.setCellHorizontalAlignment(panelLiceNumber,
				HasHorizontalAlignment.ALIGN_RIGHT);

		mainPanel.add(panel1);
		mainPanel.setCellHorizontalAlignment(panel1,
				HasHorizontalAlignment.ALIGN_RIGHT);

		HorizontalPanel panel2 = new HorizontalPanel();

		HorizontalPanel panelName = new HorizontalPanel();
		HTML htmlName = new HTML("الاسم بالعربى:");
		htmlName.setStyleName("req-title1");
		TextBox txtName = new TextBox();

		panelName.add(htmlName);
		panelName.setCellHorizontalAlignment(htmlName,
				HasHorizontalAlignment.ALIGN_RIGHT);
		panelName.add(txtName);
		panelName.setCellHorizontalAlignment(txtName,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel2.add(panelName);
		panel2.setCellHorizontalAlignment(panelName,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel2.add(new HTML("&nbsp"));
		panel2.add(new HTML("&nbsp"));
		panel2.add(new HTML("&nbsp"));

		HorizontalPanel panelTOLice = new HorizontalPanel();
		HTML htmlTOLice = new HTML("الى رقم:");
		htmlTOLice.setStyleName("req-title");
		TextBox txtTOLice = new TextBox();

		panelTOLice.add(htmlTOLice);
		panelTOLice.setCellHorizontalAlignment(htmlTOLice,
				HasHorizontalAlignment.ALIGN_RIGHT);
		panelTOLice.add(txtTOLice);
		panelTOLice.setCellHorizontalAlignment(txtTOLice,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel2.add(panelTOLice);
		panel2.setCellHorizontalAlignment(panelTOLice,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel2.add(new HTML("&nbsp"));
		panel2.add(new HTML("&nbsp"));
		panel2.add(new HTML("&nbsp"));

		HorizontalPanel panelUser = new HorizontalPanel();
		HTML htmlUser = new HTML("المستخدم");
		htmlUser.setStyleName("req-title");
		final ListBox listUser = new ListBox();
		listUser.setStyleName("req-title2");
		SearchService.Util.getInstance().getSecUsers(
				new AsyncCallback<List<SecUsers>>() {

					@Override
					public void onSuccess(List<SecUsers> result) {
						for (int i = 0; i < result.size(); i++) {
							listUser.addItem(result.get(i).getUserName(),
									result.get(i).getUserId());
						}

					}

					@Override
					public void onFailure(Throwable caught) {
						Window.alert("caught " + caught.getMessage());

					}
				});

		panelUser.add(htmlUser);
		panelUser.setCellHorizontalAlignment(htmlUser,
				HasHorizontalAlignment.ALIGN_RIGHT);
		panelUser.add(listUser);
		panelUser.setCellHorizontalAlignment(listUser,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel2.add(panelUser);
		panel2.setCellHorizontalAlignment(panelUser,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel2.add(new HTML("&nbsp"));
		panel2.add(new HTML("&nbsp"));
		panel2.add(new HTML("&nbsp"));

		HorizontalPanel panelTODate = new HorizontalPanel();
		HTML htmlToDate = new HTML("الى تاريخ:");
		htmlToDate.setStyleName("req-title1");
		DateBox datePickerToDate = new DateBox();

		panelTODate.add(htmlToDate);
		panelTODate.setCellHorizontalAlignment(htmlToDate,
				HasHorizontalAlignment.ALIGN_RIGHT);
		panelTODate.add(datePickerToDate);
		panelTODate.setCellHorizontalAlignment(datePickerToDate,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel2.add(panelTODate);
		panel2.setCellHorizontalAlignment(panelTODate,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel2.add(new HTML("&nbsp"));
		panel2.add(new HTML("&nbsp"));
		panel2.add(new HTML("&nbsp"));

		HorizontalPanel panelNational = new HorizontalPanel();
		HTML htmlNational = new HTML("الرقم القومى:");
		htmlNational.setStyleName("req-title1");
		TextBox txtNational = new TextBox();

		panelNational.add(htmlNational);
		panelNational.setCellHorizontalAlignment(htmlNational,
				HasHorizontalAlignment.ALIGN_RIGHT);
		panelNational.add(txtNational);
		panelNational.setCellHorizontalAlignment(txtNational,
				HasHorizontalAlignment.ALIGN_RIGHT);

		panel2.add(panelNational);
		panel2.setCellHorizontalAlignment(panelNational,
				HasHorizontalAlignment.ALIGN_RIGHT);

		mainPanel.add(panel2);
		mainPanel.setCellHorizontalAlignment(panel2,
				HasHorizontalAlignment.ALIGN_RIGHT);

		HorizontalPanel panel3 = new HorizontalPanel();
		Button buttonSearch = new Button("بحث");
		buttonSearch.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				SearchClientUtil.search(Integer.parseInt(txtFromLice.getText()));

			}
		});
		panel3.add(buttonSearch);
		panel3.setCellHorizontalAlignment(buttonSearch,
				HasHorizontalAlignment.ALIGN_RIGHT);

		mainPanel.add(panel3);
		mainPanel.setCellHorizontalAlignment(panel3,
				HasHorizontalAlignment.ALIGN_RIGHT);

		flexTable = new FlexTable();
		flexTable.setCellSpacing(0);
		flexTable.setCellPadding(0);
		flexTable.setWidth("100%");

		HTML html6 = new HTML("مؤكد");
		html6.setStyleName("qual-Table-data");
		HTML html7 = new HTML("المهنه");
		html7.setStyleName("qual-Table-data");
		HTML html8 = new HTML("رقم الرخصه");
		html8.setStyleName("qual-Table-data");
		HTML html9 = new HTML("الاسم");
		html9.setStyleName("qual-Table-data");
		HTML html10 = new HTML("تاريخ الرخصه");
		html10.setStyleName("qual-Table-data");
		HTML html11 = new HTML("جهة المؤهل");
		html11.setStyleName("qual-Table-data");
		HTML html12 = new HTML("الدور");
		html12.setStyleName("qual-Table-data");
		HTML html13 = new HTML("العنوان");
		html13.setStyleName("qual-Table-data");
		HTML html14 = new HTML("الصورة");
		html14.setStyleName("qual-Table-data");
		flexTable.setWidget(0, 0, html6);
		flexTable.setWidget(0, 1, html7);
		flexTable.setWidget(0, 2, html8);
		flexTable.setWidget(0, 3, html9);
		flexTable.setWidget(0, 4, html10);
		flexTable.setWidget(0, 5, html11);
		flexTable.setWidget(0, 6, html12);
		flexTable.setWidget(0, 7, html13);
		flexTable.setWidget(0, 8, html14);

		flexTable.getFlexCellFormatter().setStyleName(0, 0,
				"qual-Table-data-header");
		flexTable.getFlexCellFormatter().setStyleName(0, 1,
				"qual-Table-data-header1");
		flexTable.getFlexCellFormatter().setStyleName(0, 2,
				"qual-Table-data-header1");
		flexTable.getFlexCellFormatter().setStyleName(0, 3,
				"qual-Table-data-header1");
		flexTable.getFlexCellFormatter().setStyleName(0, 4,
				"qual-Table-data-header1");
		flexTable.getFlexCellFormatter().setStyleName(0, 5,
				"qual-Table-data-header1");
		flexTable.getFlexCellFormatter().setStyleName(0, 6,
				"qual-Table-data-header1");
		flexTable.getFlexCellFormatter().setStyleName(0, 7,
				"qual-Table-data-header1");
		flexTable.getFlexCellFormatter().setStyleName(0, 8,
				"qual-Table-data-header1");

		mainPanel.add(flexTable);
		mainPanel.setCellHorizontalAlignment(flexTable,
				HasAlignment.ALIGN_CENTER);

		initWidget(mainPanel);
	}

	public static void drawData(List<MLLicensesSearchBean> result) {

		for (int i = 0; i < result.size(); i++) {

			final int index = i;
			CheckBox html6 = new CheckBox();
			html6.setStyleName("qual-Table-data1");
			if (result.get(i).getConfirmedFlag() != null
					&& result.get(i).getConfirmedFlag()) {
				html6.setValue(true);
			}

			FocusPanel focusPanel1=new FocusPanel();
			HTML html7 = new HTML(result.get(i).getProfession());
			html7.setStyleName("qual-Table-data2");
			
			focusPanel1.add(html7);			
			focusPanel1.setHeight("50px");
			
			focusPanel1.addMouseOverHandler(new MouseOverHandler() {

				@Override
				public void onMouseOver(MouseOverEvent event) {
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 0,
							"qual-Table-data-st-over");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 1,
							"qual-Table-data-st2-over");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 2,
							"qual-Table-data-st2-over");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 3,
							"qual-Table-data-st1-over");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 4,
							"qual-Table-data-st1-over");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 5,
							"qual-Table-data-st1-over");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 6,
							"qual-Table-data-st1-over");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 7,
							"qual-Table-data-st1-over");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 8,
							"qual-Table-data-st1-over");

				}
			});
			focusPanel1.addMouseOutHandler(new MouseOutHandler() {

				@Override
				public void onMouseOut(MouseOutEvent event) {
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 0,
							"qual-Table-data-st");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 1,
							"qual-Table-data-st2");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 2,
							"qual-Table-data-st2");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 3,
							"qual-Table-data-st1");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 4,
							"qual-Table-data-st1");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 5,
							"qual-Table-data-st1");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 6,
							"qual-Table-data-st1");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 7,
							"qual-Table-data-st1");
					flexTable.getFlexCellFormatter().setStyleName(index + 1, 8,
							"qual-Table-data-st1");

				}
			});
			HTML html8 = new HTML(result.get(i).getLicenseNumber() + "");
			html8.setStyleName("qual-Table-data1");
			HTML html9 = new HTML(result.get(i).getNameA());
			html9.setStyleName("qual-Table-data1");
			HTML html10 = new HTML(result.get(i).getLicenseDate() + "");
			html10.setStyleName("qual-Table-data1");
			HTML html11 = new HTML(result.get(i).getMlQualificationsBeans()
					.get(0).getUniversity());
			html11.setStyleName("qual-Table-data1");
			HTML html12 = new HTML(result.get(i).getMlQualificationsBeans()
					.get(0).getSemester());
			html12.setStyleName("qual-Table-data1");
			HTML html13 = new HTML(result.get(i).getAddress());
			html13.setStyleName("qual-Table-data1");
			Image html14 = new Image("ImageViewServlet?imageid="
					+ result.get(i).getImageId());
			html14.setSize("50px", "50px");
			html14.setStyleName("qual-Table-data1");
			flexTable.setWidget(i + 1, 0, html6);
			flexTable.setWidget(i + 1, 1, focusPanel1);
			flexTable.setWidget(i + 1, 2, html8);
			flexTable.setWidget(i + 1, 3, html9);
			flexTable.setWidget(i + 1, 4, html10);
			flexTable.setWidget(i + 1, 5, html11);
			flexTable.setWidget(i + 1, 6, html12);
			flexTable.setWidget(i + 1, 7, html13);
			flexTable.setWidget(i + 1, 8, html14);

			flexTable.getFlexCellFormatter().setStyleName(i + 1, 0,
					"qual-Table-data-st");
			flexTable.getFlexCellFormatter().setStyleName(i + 1, 1,
					"qual-Table-data-st2");
			flexTable.getFlexCellFormatter().setStyleName(i + 1, 2,
					"qual-Table-data-st2");
			flexTable.getFlexCellFormatter().setStyleName(i + 1, 3,
					"qual-Table-data-st1");
			flexTable.getFlexCellFormatter().setStyleName(i + 1, 4,
					"qual-Table-data-st1");
			flexTable.getFlexCellFormatter().setStyleName(i + 1, 5,
					"qual-Table-data-st1");
			flexTable.getFlexCellFormatter().setStyleName(i + 1, 6,
					"qual-Table-data-st1");
			flexTable.getFlexCellFormatter().setStyleName(i + 1, 7,
					"qual-Table-data-st1");
			flexTable.getFlexCellFormatter().setStyleName(i + 1, 8,
					"qual-Table-data-st1");

			
			
			flexTable.getFlexCellFormatter().setHorizontalAlignment(i + 1, 8,
					HasHorizontalAlignment.ALIGN_CENTER);
		}
	}

}
